package com.saint.tvtest.view;

import android.content.Context;
import android.graphics.Rect;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.AdapterView;
import android.widget.ListView;

import com.saint.tvtest.Utils.AppUtils;

import static android.view.KeyEvent.KEYCODE_DPAD_CENTER;
import static android.view.KeyEvent.KEYCODE_DPAD_DOWN;
import static android.view.KeyEvent.KEYCODE_DPAD_LEFT;
import static android.view.KeyEvent.KEYCODE_DPAD_RIGHT;
import static android.view.KeyEvent.KEYCODE_DPAD_UP;
import static android.view.KeyEvent.KEYCODE_ENTER;

/**
 * Created by Administrator on 2018/2/24.
 */

public class MyListView extends ListView {
    private Context context;

    public MyListView(Context context) {
        super(context);
        this.context = context;
    }

    public MyListView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
    }

    public MyListView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
    }

    public MyListView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        this.context = context;
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KEYCODE_DPAD_CENTER) {
            Log.e("OnKeyDown", "key_center");

        } else if (keyCode == KEYCODE_ENTER) {
            Log.e("OnKeyDown", "key_Enter");
        } else if (keyCode == KEYCODE_DPAD_LEFT) {
            Log.e("OnKeyDown", "KEYCODE_DPAD_LEFT");
        } else if (keyCode == KEYCODE_DPAD_RIGHT) {
            Log.e("OnKeyDown", "KEYCODE_DPAD_RIGHT");
        } else if (keyCode == KEYCODE_DPAD_DOWN) {
            Log.e("OnKeyDown", "KEYCODE_DPAD_DOWN");
        } else if (keyCode == KEYCODE_DPAD_UP) {
            Log.e("OnKeyDown", "KEYCODE_DPAD_UP");
        }
//        if (null != context) {
            AppUtils.play();
//        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
        Log.e("OnKeyDown", "gainFocus：" + gainFocus + "    direction: " + direction);
        super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
    }

}
